import reason from '@/api/reason'

const state = {
  all: []
}

const actions = {
  addToCart ({commit}, reasons) {
    commit('add_to_cart', reasons.id)
  },
  getAllReasons ({commit}) {
    reason.getReasons(reasons => {
      commit('receive_reasons', reasons)
    })
  }
}

const mutations = {
  receive_reasons (state, reasons) {
    state.all = reasons
  },
  add_to_cart (state, reasonsId) {
    state.all.find(r => r.id === reasonsId).inventory--
  }
}
const getters = {
  allReasons (state) {
    return state.all
  }
}
export default {
  state,
  actions,
  mutations,
  getters
}
